package org.apache.flink.runtime.resourcemanager.registration;

import org.apache.flink.api.common.ConsumerID;
import org.apache.flink.runtime.clusterframework.types.ResourceID;
import org.apache.flink.runtime.resourceconsumer.ResourceConsumerGateway;
import org.apache.flink.runtime.resourceconsumer.ConsumingMasterId;
import org.apache.flink.util.Preconditions;

/**
 * Container for JobManager related registration information, such as the leader id or the consumer id.
 */
public class ResourceConsumerRegistration {
    private final ConsumerID consumerID;

    private final ResourceID resourceConsumerResourceID;

    private final ResourceConsumerGateway resourceConsumerGateway;

    public ResourceConsumerRegistration(
            ConsumerID jobID, ResourceID jobManagerResourceID, ResourceConsumerGateway resourceConsumerGateway) {
        this.consumerID = Preconditions.checkNotNull(jobID);
        this.resourceConsumerResourceID = Preconditions.checkNotNull(jobManagerResourceID);
        this.resourceConsumerGateway = Preconditions.checkNotNull(resourceConsumerGateway);
    }

    public ConsumerID getJobID() {
        return consumerID;
    }

    public ResourceID getResourceConsumerResourceID() {
        return resourceConsumerResourceID;
    }

    public ConsumingMasterId getConsumerMasterId() {
        return resourceConsumerGateway.getFencingToken();
    }

    public ResourceConsumerGateway getResourceConsumerGateway() {
        return resourceConsumerGateway;
    }
}
